﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BGCOP.CAVTOP.BUSINESSLAYER
{
    public class Tarjetas
    {
        public List<TTarjeta> ListarTodas()
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                var usrs = from usr in db.TTarjeta 
                           select usr;
                return usrs.ToList();
            }
        }
        public List<TTarjeta> ListarTodasActivas()
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                var usrs = from usr in db.TTarjeta where usr.esutilizada != true 
                           select usr;
                return usrs.ToList();
            }
        }
        public void crearTarjeta(string cad)
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                var mm = new TTarjeta()
                             {
                                 numtarjeta = cad,
                                 activa = true
                             };
                db.AddToTTarjeta(mm);
                db.SaveChanges();
            }
        }
        public void asignartarjetaempleado(string tarjetaS, int id)
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                var tobj = (from a in db.TTarjeta where a.numtarjeta == tarjetaS select a).FirstOrDefault();
                var emp = (from b in db.TEmpleado where b.idEmpleado == id select b).FirstOrDefault();
                emp.idTarjeta = tobj.idTarjeta;
                db.SaveChanges();
            }
        }
        public void asignartarjetaempleado(int tarjetaI, int id)
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                
                var emp = (from b in db.TEmpleado where b.idEmpleado == id select b).FirstOrDefault();
                emp.idTarjeta = tarjetaI;
                db.SaveChanges();
            }
        }
    }
}
